/**
   * Return the hemisphere abbreviation for this coordinate.
   */
getHemi = function(coordinate, type) {
    var coordinatehemi = "";
    if (type == 'LAT') {
        if (coordinate >= 0) {
            coordinatehemi = "N";
        }
        else {
            coordinatehemi = "S";
        }
    }
    else if (type == 'LON') {
        if (coordinate >= 0) {
            coordinatehemi = "E";
        } else {
            coordinatehemi = "W";
        }
    }

    return coordinatehemi;
};


/**
   * Decimal to DMS conversion
   */
convertDMS = function(coordinate, type) {
    var coords = new Array();

    abscoordinate = Math.abs(coordinate)
    coordinatedegrees = Math.floor(abscoordinate);

    coordinateminutes = (abscoordinate - coordinatedegrees)/(1/60);
    tempcoordinateminutes = coordinateminutes;
    coordinateminutes = Math.floor(coordinateminutes);
    coordinateseconds = (tempcoordinateminutes - coordinateminutes)/(1/60);
    coordinateseconds =  Math.round(coordinateseconds*10);
    coordinateseconds /= 10;

    if( coordinatedegrees < 10 )
        coordinatedegrees = "0" + coordinatedegrees;
    coordinatedegrees += "°";
    if( coordinateminutes < 10 )
        coordinateminutes = "0" + coordinateminutes;
    coordinateminutes += "'";
    if( coordinateseconds < 10 )
        coordinateseconds = "0" + coordinateseconds;
    coordinateseconds += "''";
    coords[0] = coordinatedegrees;
    coords[1] = coordinateminutes;
    coords[2] = coordinateseconds;
    coords[3] = this.getHemi(coordinate, type);

    return coords;
};
function createDialog(title,text,closeFunction){
    
    var dialog = $('<div/>').attr('id','customDynamicDialog');
    var dialogContent = $('<p></p>').text(text).css('text-align','center');
    
    dialogContent.appendTo(dialog);
    dialog.appendTo(document.body);

    dialog.dialog({
        width: 'auto',
        height: 'auto',
        modal:true,
        title: title,
        buttons:[{
            text: 'Aceptar', 
            click: function() {
                
                $(this).dialog('close');
            }
        }
      
        ],
        close: closeFunction ? closeFunction : function(e) {
            $(this).html('');
        }
    });
}
